package org.jetnuke.modules.admin.preferences;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.velocity.VelocityContext;
import org.jetnuke.common.ActionForward;
import org.jetnuke.common.IAction;
import org.jetnuke.common.IAdminInfo;
import org.jetnuke.common.IModuleInfo;
import org.jetnuke.common.IUserInfo;
import org.jetnuke.dao.DataAccessDriver;
import org.jetnuke.entities.MainConfig;
import org.jetnuke.repository.MainConfigRepository;
import org.jetnuke.util.JetUtil;

public class PreferencesUpdate implements IAction {
	String sitename, url, style,footer1,footer2,footer3,locale;
	int xtop,xstoryhome,xadmingraphic;
	
	public void setXtop(int xtop) {
		this.xtop = xtop;
	}
	int censormode;

	String censorReplace;

	String adminmail;
	int useFlags;

	public void setUseFlags(int useFlags) {
		this.useFlags = useFlags;
	}
	public void setArticlecomm(int articlecomm) {
		this.articlecomm = articlecomm;
	}

	public void setPollcomm(int pollcomm) {
		this.pollcomm = pollcomm;
	}

	int articlecomm, pollcomm;

	public void setAdminmail(String adminmail) {
		this.adminmail = adminmail;
	}

	/**
	 * @param sitename
	 *            The sitename to set.
	 */
	public void setSitename(String sitename) {
		this.sitename = sitename;
	}

	/**
	 * @param url
	 *            The url to set.
	 */
	public void setUrl(String url) {
		this.url = url;
	}

	public ActionForward exec(HttpServletRequest request,
			HttpServletResponse response, VelocityContext vc, IModuleInfo info,
			String op, IUserInfo ui, IAdminInfo ai) throws Exception {

		if (ai == null || !ai.IsSuperUser())
			return null;//Error;

		MainConfig config = DataAccessDriver.getInst().newMainConfigDAO().getMainConfig();
		config.setSITENAME(sitename);
		config.setNUKEURL(url);
		config.setDEFAULT_THEME(style);
		config.setCENSORMODE(censormode);
		config.setCENSORREPLACE(censorReplace);
		config.setADMINMAIL(adminmail);
		config.setPOLLCOMM(pollcomm);
		config.setARTICLECOMM(articlecomm);
		config.setUSEFLAGS(useFlags);
		config.setTOP(xtop);
		config.setSTORYHOME(xstoryhome);
		config.setADMINGRAPHIC(xadmingraphic);
		config.setFOOT1(footer1);
		config.setFOOT2(footer2);
		config.setFOOT3(footer3);
		config.setLOCALE(locale);
		DataAccessDriver.getInst().newMainConfigDAO().update(config);
		MainConfigRepository.clearCache();
		//config.save();
		JetUtil.redirect(vc,response,request.getContextPath()+"/do/admin/preferences");
		return null;
	}

	public void setCensormode(int censormode) {
		this.censormode = censormode;
	}

	public void setCensorReplace(String censorReplace) {
		this.censorReplace = censorReplace;
	}

	/**
	 * @param style
	 *            The style to set.
	 */
	public void setStyle(String style) {
		this.style = style;
	}
	public void setXstoryhome(int xstoryhome) {
		this.xstoryhome = xstoryhome;
	}
	public void setXadmingraphic(int xadmingraphic) {
		this.xadmingraphic = xadmingraphic;
	}
	public void setFooter1(String footer1) {
		this.footer1 = footer1;
	}
	public void setFooter2(String footer2) {
		this.footer2 = footer2;
	}
	public void setFooter3(String footer3) {
		this.footer3 = footer3;
	}
	public void setLocale(String locale) {
		this.locale = locale;
	}
}
